<?php

class PackageController extends Controller {
    private $packageService = null;
    public function __construct($id, $module = null) {
        parent::__construct($id, $module);
        $this->packageService = new PackageService();
    }

    public function actionListForPublic() {
        $result = $this->packageService->getListForPublic();
        if(is_int($result)){
            JSONHelper::echoJSON(FALSE,$result);
        } 
        JSONHelper::echoJSON(true,$result);
    }
    
    public function actionGetDetailById()
    {
        if(!isset($_GET["id"])){
            JSONHelper::echoJSON(false,  JSONHelper::ERROR_ILLEGAL_REQUEST);
        }
        $result = $this->packageService->getDetailById($_GET["id"]);
        if(is_int($result)){
            JSONHelper::echoJSON(FALSE,$result);
        }
        $result["centers"] = $this->renderPartial("centersDetail",array("centers"=>$result["centers"]),true);
        $result["examitems"] = $this->renderPartial("examitems",array("examitems"=>$result["examitems"]),true);
       	$result["introduce"] = $this->renderPartial("centersIntroduce",array("introduce"=>$result['introduce']),true);
        JSONHelper::echoJSON(true,$result);
    }
}